import os

from django.conf import settings
from django.views import View

from User.models import Order
from Venue import Constants
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredVenue


class OrderView(LoginRequiredVenue,View):
    """ 订单 """

    def get(self, request):
        """ 查询 """
        type = request.GET.get('type')


        orders = Order.objects.order_by("-createTime")
        if type:
            if int(type) not in Order.OrderType.list():
                return Res.Json(Res.ParamErr)
            orders = orders.filter(type=type)

        lists = []
        for order in orders.all():
            lists.append(order.Info())
        return Res.Json(Res.OK, result=lists)
